<template>
   <div class="goods-list">
       <!-- 跳转页面有两种方式，一种是利用标签，比如a链接，还有一种是用编程js代码实现跳转 -->
       <!-- window.location.href 这种方法要操作dom，在vue里面不能使用，vue-router里面提供了一种跳转方法 替代 -->
        <!-- <router-link class="goods-item" v-for="item in goodslist" :key="item.goodsId" :to="'/home/goodsinfo/' + item.goodsId "> -->
        <div class="goods-item" v-for="item in goodslist" :key="item.goodsId" @click="getdetail(item.goodsId)">
        <img :src="item.image" alt="">
        <h1 class="title">{{ item.name }}</h1>
        <div class="info">
            <p class="price">
                <span class="now">
                    {{ item.mallPrice }}
                    
                </span>
                <span class="old">
                 {{ item.price }}
                    
                </span>
            </p>
             
            <p class="sell">
                <span>热卖中</span>
                <span>剩60件</span>
               
            </p>

        </div>
            </div>
        
        <!-- </router-link> -->
    <mt-button type="danger" size="large">加载更多</mt-button>
   
    
   </div>
    
</template>
<script>
export default {
    data(){
        //data是往自己组建内部挂载一些私有数据
        return{
            goodslist:[]

        }
    },
    created(){
        this.getgoodlist()

    },
    methods:{
        getgoodlist(){
            //获取商品列表
            this.$http.get('https://www.easy-mock.com/mock/5c05f6478da5aa5aaa8b6076/vue').then(result =>{
                console.log(result)
                this.goodslist = result.body.data.hotGoods

            })
        },
        getdetail(goodsId){
            //使用编程代码的方式进行页面的跳转
            console.log(this)
            // this.$router.push('/home/goodsinfo/' + goodsId)
            //使用编程代码方式进行跳转的第二种方式.传入一个名字。这个名字router。js里面命名的路由匹配规则
            this.$router.push( { name:'goodsinfo', params:{ goodsId }})


        }

    },

    
}
</script>
<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 7px;
    justify-content: space-between;
    .goods-item{
        width: 49%;
        border:1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin: 4px 0;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 293px;       
         img{
            width: 100%;
        }
        .title{
            font-size: 14px;
        }
        .info{
            background-color: #eee;
            p{
                margin: 0;
               padding: 5px;
            }
            .price{
                .now{
                    color:red;
                    font-weight: bold;
                    font-size: 16px;

                }
                .old{
                    text-decoration: line-through;
                    font-size:12px;
                    margin-left:10px;

                }

            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size:13px;

            }
        }
    }
        
    }

</style>



